package com.mojavelinux.open18;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;

import org.appfuse.dao.GenericDao;
import org.appfuse.service.impl.GenericManagerImpl;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

public class CourseManager extends GenericManagerImpl<Course, Long> {

	// make CGLIB happy, feed it a default constructor
	public CourseManager() {
		super( null );
	}
	
	public CourseManager( GenericDao<Course, Long> courseDao ) {
		super( courseDao );
	}
	
	// NOTE: run the result through a set filter to weed out duplicates that are
	// artifacts of eager fetching optimizations.
	@Transactional( readOnly = true, propagation = Propagation.REQUIRED )
	public List<Course> getAll() {
		return new ArrayList<Course>( new LinkedHashSet<Course>( super.getAll() ) );
	}

	@Transactional( readOnly = true, propagation = Propagation.REQUIRED )
	public Course get( Long id ) {
		Course course = super.get( id );
		// initialize collections to fully load course info
		course.getHoles().size();
		course.getTeeSets().size();
		return course;
	}

}
